﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Person
{
    class Person
    {
        private string firstName = null;
        private string lastName = null;
        private string gender = null;
        private string birthDate = null;

        public string FirstName
        {
            get { return this.firstName; }
            set
            {
                if (value != null && this.firstName != value)
                {
                    this.firstName = value;
                    OnFirstNameChanged();
                }
            }
        }
        public string LastName
        {
            get { return this.lastName; }
            set
            {
                if (value != null && this.lastName != value)
                {
                    this.lastName = value;
                    OnLastNameChanged();
                }
            }
        }
        public string Gender
        {
            get { return this.gender; }
            set
            {
                if (value != null && this.gender != value)
                {
                    this.gender = value;
                    OnGenderChanged();
                }
            }
        }
        public string BirthDate
        {
            get { return this.birthDate; }
            set
            {
                if (value != null && this.birthDate != value)
                {
                    this.birthDate = value;
                    OnBirthDateChanged();
                }
            }
        }

        public event EventHandler FirstNameChangedEventHandler;
        public event EventHandler LastNameChangedEventHandler;
        public event EventHandler GenderChangedEventHandler;
        public event EventHandler BirthDateChangedEventHandler;

        public Person(string firstName, string lastName, string gender, string birthDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.gender = gender;
            this.birthDate = birthDate;

            this.FirstNameChangedEventHandler = 
                new EventHandler((x, y) => Console.WriteLine("First name was changed"));
            this.LastNameChangedEventHandler = 
                new EventHandler(delegate(object sender, EventArgs args) { Console.WriteLine("Last name was changed"); });
            this.GenderChangedEventHandler = 
                new EventHandler(delegate(object sender, EventArgs args) { Console.WriteLine("Gender was changed"); });
            this.BirthDateChangedEventHandler = 
                new EventHandler((x, y) => Console.WriteLine("Birth date was changed"));
        }

        protected void OnFirstNameChanged()
        {
            if (FirstNameChangedEventHandler != null)
            {
                FirstNameChangedEventHandler.Invoke(this, null);
            }
        }

        protected void OnLastNameChanged()
        {
            if (LastNameChangedEventHandler != null)
            {
                LastNameChangedEventHandler.Invoke(this, null);
            }
        }

        protected void OnGenderChanged()
        {
            if (GenderChangedEventHandler != null)
            {
                GenderChangedEventHandler.Invoke(this, null);
            }
        }

        protected void OnBirthDateChanged()
        {
            if(BirthDateChangedEventHandler != null)
            {
                BirthDateChangedEventHandler.Invoke(this, null);
            }
        }
    }
}
